Implements basic BOM/Codec detection, PEP compliance and style guide pass, Python3 modernisation #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I guess im coming back to this old project again haha.
I noted that if you accidentally specified the wrong codec, Python would not appropriately strip the BOM char out of the file, which would result in the regex to identify the first Key failing to match because the line didn't start with a
"
. 99% of the time, you will be fine just using the default UTF8, but sometimes Valve throws a curveball at you with a Source 1 UTF-16 encoded file.The current implementation will pick up a BOM char if it exists, and convert that to the appropriate encoding string, then will drop a warning about overriding the specified encoding with the new one. You can override this by using the
ignore_bom=True
flag in class init.I also ran some styling sweeps over the file to make it a little more happy with the PEP style guides, and removed references to Py2 functions. If you want to keep Py2 support, then I can go back and do some proper Py2/3 inter-support with the futures/futurize package.
Happy to take comments/feedback on this and make changes as needed.